﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.views.windows.sun {
    import flash.events.*;
    import flash.display.*;
    import net.wooga.pets.views.windows.*;
    import net.wooga.pets.events.windows.*;
    import net.wooga.pets.models.windows.sun.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.constants.windows.*;

    public class SunWindowsMediator extends Mediator {

        private var _mainRenderView:SunWindowsContainer;
        private var _windowsModel:SunWindowsModel;

		[Inject]
        public function set sunWindowsModel(_arg1:SunWindowsModel):void{
            this._windowsModel = _arg1;
        }
		[Inject]
        public function set windowRenderView(_arg1:SunWindowsContainer):void{
            this._mainRenderView = _arg1;
        }
        override public function onRegister():void{
            this.eventMap.mapListener(eventDispatcher, WindowsEventConstants.NOTIFICATION_VIEW_ADDED_TO_STAGE, this.onWindowViewAddedDetected);
            this.eventMap.mapListener(eventDispatcher, WindowsEventConstants.NOTIFICATION_VIEW_REMOVED_FROM_STAGE, this.onWindowViewRemovedDetected);
            this.eventMap.mapListener(eventDispatcher, WindowsMainViewUpdateEvent.ADD_SUN_WINDOW, this.onWindowAddRequest, WindowsMainViewUpdateEvent);
            this.eventMap.mapListener(eventDispatcher, WindowsMainViewUpdateEvent.REMOVE_ALL_SUN_WINDOWS, this.onClearAllWindowsEventReceived);
            this.eventMap.mapListener(eventDispatcher, EventConstants.INIT_WORLD_COMPLETE, this.onInitWorldCheckForWindows);
        }
        private function onClearAllWindowsEventReceived(_arg1:WindowsMainViewUpdateEvent):void{
            dispatch(new Event(GameConstants.SUN_STOP_TALKING));
        }
        private function onInitWorldCheckForWindows(_arg1:Event):void{
            this.updateSunTalkingState();
        }
        private function updateSunTalkingState():void{
            if (this._windowsModel.activeWindows == 1){
                dispatch(new Event(GameConstants.SUN_START_TALKING));
            } else {
                dispatch(new Event(GameConstants.SUN_STOP_TALKING));
            };
        }
        private function onWindowAddRequest(_arg1:WindowsMainViewUpdateEvent):void{
            var _local2:IWindowView = _arg1.window;
            this.view.addChild((_local2 as Sprite));
        }
        private function onWindowViewAddedDetected(_arg1:Event):void{
            this.updateSunTalkingState();
        }
        private function onWindowViewRemovedDetected(_arg1:Event):void{
            var _local2:IWindowView = (_arg1.target as IWindowView);
            this.updateSunTalkingState();
        }
        private function get view():Sprite{
            return ((this._mainRenderView as Sprite));
        }

    }
}//package net.wooga.pets.views.windows.sun 
